package com.api.rest.context;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by dan3652@sina.com on 2016-12-02 10:47.
 */
public class RestContextInterceptor extends HandlerInterceptorAdapter {
    private static final String SIGN = "sign";
    private static final String APPKEY = "app_key";
    private static final String TIMESTAMP = "timestamp";
    private static final String METHOD = "method";
    private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    private static final long TIME = 20 * 60 * 1000;

    @Override
    public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request,HttpServletResponse response, Object handler, ModelAndView mav) throws Exception {
//		System.out.println(request.getRequestURL());
        String[] str = request.getRequestURI().split("rest");
        // 有机会修改ModelAndView
        // 操作成功，重新跳转
		/*Map map = new HashMap();
		map.put("errcode", "0");
		map.put("errmsg", "SUCCESS");
		Map model = new HashMap(mav.getModel());
		map.put("rows", model);
		mav.getModel().clear();
		mav.getModelMap().putAll(map);*/
    }

    @Override
    public void afterCompletion(HttpServletRequest request,HttpServletResponse response, Object handler, Exception ex) throws Exception {
        String message = null;
    }

    public void setAuth(boolean auth) {
//		System.out.println("auth:"+auth);
        this.auth = auth;
    }

    private boolean auth = false;
}
